$(function(){
    $("#pathUp").text('用户');
    $("#pathDown").text('用户详情');
    $("#saveBtn").click(function () {
        var validate = $("#addFrom").validate({
            debug: false,
            rules: {
                "userName": {
                    required: true,
                    remote: {
                        url: window.ctx + "/rest/user/checkName",
                        type: "post",
                        dataType: "json",
                        data: {
                            userName: function () {
                                return $("[name=userName]").val();
                            }
                        },
                    }
                },
                "password":{
                    required:true
                },
                "phone":{
                    isPhone:true
                },
                "realName":{
                    required:true
                }
            },
            messages: {
                userName: {
                    required: "用户名不能为空",
                    remote: "用户名已存在",
                },
                password:{
                    required:"密码不能为空",
                },
                realName:{
                    required:"真实姓名不能为空",
                }
            },
            submitHandler: function () {
                var roleList = new Array();
                $("input[name='rids']:checked").each(function () {
                    roleList.push($(this).val());
                });
                var param = {id: $("[name=id]").val()};
                param["userName"] = $("[name=userName]").val();
                param["password"] = $("[name=password]").val();
                param["status"] = $("[name = status]").val();
                param["phone"] = $("[name = phone]").val();
                param["realName"] = $("[name = realName]").val();
                param["roleItem"] = $("input[name='rids']:checked").val();
                $.ajax({
                    type: "post",
                    url: window.ctx + "/rest/user/saveUser",
                    contentType : "application/json",
                    data: JSON.stringify(param),
                    datatype: "json",
                    success: function (data) {
                        art.dialog.tips('修改信息成功!');
                       // setTimeout("location.reload()", 1000);//页面刷新
                        window.location.href = window.ctx +"/user/list";
                    },
                    error: function (data) {
                        art.dialog.tips('修改信息失败!');
                    }
                });
            }
        });
    });
    $("#backBtn").click(function () {
       window.location.href = window.ctx +"/user/list";
    });
})